var ChargeDialogWidth = 800; //收费dialog窗口宽度
var ChargeDialogHeight = 290; //收费dialog窗口高度
$(document).ready(function() {
	///自动计算应收金额
	$("#ff .feeinput").textbox({
		onChange: function(newValue, oldValue) {
			var n = newValue;
			var o = oldValue;
			var sum = 0;
			if(n != o) {
				$("#ff .feeinput").each(function(index) {
					s = $(this).textbox('getValue');
					if(s != "") {
						sum += parseFloat(s);
					}

				});
				$("#input_SUM").textbox('setValue', sum);
			}
		}
	});

});
//租户姓名模糊查询

function iniStateCombobox() {
	$('#input_STATE').combobox({
		valueField: 'ID',
		textField: 'NAME',
		panelHeight: 'auto',
		data: [{
			"ID": "在用",
			"NAME": "在用"
		}, {
			"ID": "停用",
			"NAME": "停用"
		}, {
			"ID": "包库",
			"NAME": "包库"
		}]
	});
}

function createTenantCombobox() {
	$('#input_TENANT_NAME').combobox({
		valueField: 'TENANT_NAME',
		textField: 'TENANT_NAME',
		panelHeight: 'auto',
		mode: 'remote',
		method: 'get',
		onChange: function(newValue, oldValue) {
			if(!isEnglish(newValue)) {
				return;
			}
			if(newValue != "" && newValue != undefined) {
				var url = RemoteLinkAddress + "/frozen/tenant/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
				$(this).combobox("reload", url);
			}
		},
		onSelect: function(record) {
			$('#input_TENANT_ID').textbox("setValue", record.ID);
		}
	});
}

function createShoreHouseCombobox() {
	$("#input_STOREHOUSE_NAME").combobox({
		valueField: 'NAME',
		textField: 'NAME',
		panelHeight: '100',
		mode: 'remote',
		method: 'get',
		url: RemoteLinkAddress + "/frozen/storehouse/listall.do?STATE=在用",
		onSelect: function(record) {
			$("#input_STOREHOUSE_ID").textbox('setValue', record.ID);
			$("#input_DUTYMAN").textbox("setValue", record.CHARGER);
		}
	})
}

function createShoreHouseComboboxByID() {
	$("#input_STOREHOUSE_NAME").combobox({
		valueField: 'ID',
		textField: 'NAME',
		panelHeight: '100',
		mode: 'remote',
		method: 'get',
		url: RemoteLinkAddress + "/frozen/storehouse/listall.do?STATE=在用",
		onSelect: function(record) {
			$("#input_STOREHOUSE_ID").textbox('setValue', record.ID);
			$("#input_DUTYMAN").textbox("setValue", record.CHARGER);
		}
	})
}

function createGoodCombobox() {
	$("#input_GOODS_NAME").combobox({
		valueField: 'NAME',
		textField: 'NAME',
		panelHeight: 'auto',
		mode: 'remote',
		method: 'get',
		onChange: function(newValue, oldValue) {
			if(!isEnglish(newValue)) {
				return;
			}
			if(newValue != "" && newValue != undefined) {
				var url = RemoteLinkAddress + "/frozen/goods/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
				$(this).combobox("reload", url);
			}
		},
		onSelect: function(record) {
			$("#input_GOODS_ID").textbox('setValue', record.ID);
			$("#input_SPEC").textbox('setValue', record.SPEC); //规格
			$("#input_UNIT").textbox('setValue', record.UNIT); //单位
		}
	});
}

function createIsChargeCombobox() {
	$('#input_ISCHARGE').combobox({ //是否收费
		valueField: 'ID',
		textField: 'NAME',
		panelHeight: '150',
		disabled: true,
		data: [{
			"ID": "0",
			"NAME": "否"
		}, {
			"ID": "1",
			"NAME": "是"
		}]
	});
}

function IsChargeState(_val) {
	if(_val == 0) {
		return "未收费";
	} else {
		return "已收费";
	}
}

function initWriteOffAndOutCombobox() {
	var data;
	var parentLocation;
	parentLocation = searchParent("LeasingOperationDetail.html");
	data = parentLocation.ReturnDetailData();
	createChargeCombobox();
	$('#input_CHARGER').combobox('loadData', createChargeData(data));
	$("#input_ORDER_ID").val(data.ID);
	$("#input_STOREHOUSE_ID").val(data.STOREHOUSE_ID)
}

function createChargeCombobox() {
	$('#input_CHARGER').combobox({ //选择出库人
		valueField: 'text',
		textField: 'text',
		panelHeight: 'auto',
		onSelect: function(record) {
			$('#input_CHARGER_ID').textbox("setValue", record.value);
		}

	});
}

function createChargeData(_data) {
	var FieldList = [{
			"ID": "TENANT_ID",
			"NAME": "TENANT_NAME"
		},
		{
			"ID": "PARTNER1_ID",
			"NAME": "PARTNER1"
		},
		{
			"ID": "PARTNER2_ID",
			"NAME": "PARTNER2"
		},
		{
			"ID": "PARTNER3_ID",
			"NAME": "PARTNER3"
		},
	];
	var comboboxData = new Array();
	var _index = 0;
	for(var i = 0; i < FieldList.length; i++) {
		for(s in _data) {
			if(s == FieldList[i].ID) {
				if(_data[s] != 0) {
					comboboxData[_index] = new Object();
					comboboxData[_index].text = _data[FieldList[i].NAME];
					comboboxData[_index].value = _data[FieldList[i].ID];
					_index = _index + 1;
				}
			}
		}
	}
	return comboboxData;
}

function getModiDateAuth()
{
	_data = localStorage.getItem('currRight');
	if(_data != null) {
		var authorityList = JSON.parse(_data);
		var authorityArray = $.grep(authorityList, function(value) {
			return value.parent == "LeasingOperation";
		});
		if(authorityArray.length>0)
		{
			if(authorityArray[0].hasQs==true)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	}
}
